package com.stlm2.dems.service;

import com.stlm2.util.Convert;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;

import com.stlm2.dems.entity.Flux;
import com.stlm2.dems.dao.FluxDao;
import com.stlm2.core.base.BaseDao;
import com.stlm2.core.base.impl.BaseServiceImpl;
import org.springframework.ui.ModelMap;

import java.util.ArrayList;
import java.util.List;

@Service("fluxService")
@Transactional(rollbackForClassName={"java.lang.Exception"}, propagation = Propagation.REQUIRED)
public class FluxService extends BaseServiceImpl<Flux> {

	@Resource
	private FluxDao fluxDao;

	@Override
	protected BaseDao <Flux> getDao() {
		return fluxDao;
	}

	public List<ModelMap> convertModel(List<Flux> fluxes) {
		List<ModelMap> list = new ArrayList<ModelMap>();
		if (fluxes != null && fluxes.size() > 0) {
			for (Flux flux : fluxes) {
				ModelMap map = buildModel(flux);
				list.add(map);
			}
		}
		return list;
	}

	public ModelMap buildModel(Flux flux) {
		ModelMap model = new ModelMap();
		model.put("id",flux.getId());
		model.put("flux",flux.getFlux());
		model.put("money",flux.getMoney());
		model.put("state",flux.getState()==1?"有效":"无效");
		model.put("createTime", Convert.toFullYMDHMS(flux.getCreateTime()));
		model.put("stateValue",flux.getState());
		return  model;
	}
}